<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:replace="~{common/header :: commonHead}"></head>
<META HTTP-EQUIV="Cache-Control" CONTENT= "no-cache, must-revalidate">
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight"  th:with="page=${pageObj.page},size=${pageObj.pageSize},total=${pageObj.total},totalPage=${pageObj.totalPage},keyword=${pageObj.keyword},fromDate=${pageObj.fromDate},toDate=${pageObj.toDate},fromInt=${pageObj.fromInt},toInt=${pageObj.toInt}">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>会员列表</h5>
                    <div class="ibox-tools">

                        <shiro:hasPermission name="add_user">
                            <a href=""  class="modal-trigger" data-toggle="modal" data-target="#addUser" title="手动添加用户"><i class="glyphicon glyphicon-plus-sign"></i></a>
                        </shiro:hasPermission>
                        <shiro:hasPermission name="export_user">
                            <a class="button" th:href="${'/user/export?total='+total+'&keyword='+(keyword==null?'':keyword)+'&fromDate='+(fromDate==null?'':fromDate)+'&toDate='+(toDate==null?'':toDate)+'&fromInt='+(null==fromInt?'':fromInt) +'&toInt='+(null==toInt?'':toInt)}" title="导出数据"><i class="glyphicon glyphicon-export"></i></a>
                        </shiro:hasPermission>
                            <a class="button" href="javascript: window.location.href='/user/list';" title="刷新"><i class="glyphicon glyphicon-repeat"></i></a>

                    </div>
                </div>
                <div class="ibox-content">
                    <div class="">
                    </div>
                    <div id="editable_wrapper" class="dataTables_wrapper form-inline" role="grid">
                        <div class="row">
                            <div class="col-sm-3">
                                <div class="dataTables_length" id="editable_length"><label>每页
                                <select name="editable_length" aria-controls="editable" class="form-control input-sm" id="page_size_selector">
                                    <option th:selected="${size eq 5}" value="5">5</option>
                                    <option th:selected="${size eq 10}" value="10">10</option>
                                    <option th:selected="${size eq 25}" value="25">25</option>
                                    <option th:selected="${size eq 50}" value="50">50</option>
                                    <option th:selected="${size eq 100}" value="100">100</option>
                                </select> 条记录</label>
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="input-daterange input-group">
                                    <input onkeyup="value=value.replace(/[^\d]/g,'')" type="text" class="input-sm form-control" name="start" id="from_int" placeholder="输入最小积分" th:value="${pageObj.fromInt}">
                                    <span class="input-group-addon">到</span>
                                    <input onkeyup="value=value.replace(/[^\d]/g,'')" type="text" class="input-sm form-control" name="end" id="to_int" placeholder="输入最大积分" th:value="${pageObj.toInt}">
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="input-daterange input-group" id="datepicker">
                                    <input type="text" class="input-sm form-control" name="start" id="start_date" placeholder="开始时间" autocomplete="off" th:value="${pageObj.fromDate}">
                                    <span class="input-group-addon">到</span>
                                    <input type="text" class="input-sm form-control" name="end" id="end_date" placeholder="结束时间" autocomplete="off" th:value="${pageObj.toDate}">
                                </div>
                            </div>
                            <div class="col-sm-3">
                                <div class="input-group" style="float: right">
                                    <input th:value="${keyword}" type="text" placeholder="手机号/姓名/用户名/卡号/等级" class="input-sm form-control" id="search_bar">
                                    <span class="input-group-btn">
                                        <button type="button" class="btn btn-sm btn-primary" id="search-btn"> 搜索</button>
                                    </span>
                                </div>
                            </div>
                        </div>
                        <div class="datepicker datepicker-dropdown dropdown-menu datepicker-orient-left datepicker-orient-bottom" style="display: none; top: 901.2px; left: 264.8px; z-index: 10;"><div class="datepicker-days" style="display: block;"><table class=" table-condensed"><thead><tr><th class="prev" style="visibility: visible;">«</th><th colspan="5" class="datepicker-switch">十一月 2014</th><th class="next" style="visibility: visible;">»</th></tr><tr><th class="dow">日</th><th class="dow">一</th><th class="dow">二</th><th class="dow">三</th><th class="dow">四</th><th class="dow">五</th><th class="dow">六</th></tr></thead><tbody><tr><td class="old day">26</td><td class="old day">27</td><td class="old day">28</td><td class="old day">29</td><td class="old day">30</td><td class="old day">31</td><td class="day">1</td></tr><tr><td class="day">2</td><td class="day">3</td><td class="day">4</td><td class="day">5</td><td class="day">6</td><td class="day">7</td><td class="day">8</td></tr><tr><td class="day">9</td><td class="day">10</td><td class="selected day">11</td><td class="range day">12</td><td class="range day">13</td><td class="range day">14</td><td class="range day">15</td></tr><tr><td class="range day">16</td><td class="active selected day">17</td><td class="day">18</td><td class="day">19</td><td class="day">20</td><td class="day">21</td><td class="day">22</td></tr><tr><td class="day">23</td><td class="day">24</td><td class="day">25</td><td class="day">26</td><td class="day">27</td><td class="day">28</td><td class="day">29</td></tr><tr><td class="day">30</td><td class="new day">1</td><td class="new day">2</td><td class="new day">3</td><td class="new day">4</td><td class="new day">5</td><td class="new day">6</td></tr></tbody><tfoot><tr><th colspan="7" class="today" style="display: none;">今天</th></tr><tr><th colspan="7" class="clear" style="display: none;">清空</th></tr></tfoot></table></div><div class="datepicker-months" style="display: none;"><table class="table-condensed"><thead><tr><th class="prev" style="visibility: visible;">«</th><th colspan="5" class="datepicker-switch">2014</th><th class="next" style="visibility: visible;">»</th></tr></thead><tbody><tr><td colspan="7"><span class="month">1</span><span class="month">2</span><span class="month">3</span><span class="month">4</span><span class="month">5</span><span class="month">6</span><span class="month">7</span><span class="month">8</span><span class="month">9</span><span class="month">10</span><span class="month active">11</span><span class="month">12</span></td></tr></tbody><tfoot><tr><th colspan="7" class="today" style="display: none;">今天</th></tr><tr><th colspan="7" class="clear" style="display: none;">清空</th></tr></tfoot></table></div><div class="datepicker-years" style="display: none;"><table class="table-condensed"><thead><tr><th class="prev" style="visibility: visible;">«</th><th colspan="5" class="datepicker-switch">2010-2019</th><th class="next" style="visibility: visible;">»</th></tr></thead><tbody><tr><td colspan="7"><span class="year old">2009</span><span class="year">2010</span><span class="year">2011</span><span class="year">2012</span><span class="year">2013</span><span class="year active">2014</span><span class="year">2015</span><span class="year">2016</span><span class="year">2017</span><span class="year">2018</span><span class="year">2019</span><span class="year new">2020</span></td></tr></tbody><tfoot><tr><th colspan="7" class="today" style="display: none;">今天</th></tr><tr><th colspan="7" class="clear" style="display: none;">清空</th></tr></tfoot></table></div></div>
                        <table class="table table-striped table-bordered table-hover  dataTable" id="editable"
                               aria-describedby="editable_info">
                            <thead>
                                <tr role="row">
                                    <th aria-label="会员卡号" style="width: 10%;">会员卡号</th>
                                    <th aria-label="用户名" style="width: 15%;">用户名</th>
                                    <th aria-label="姓名" style="width: 15%;">姓名</th>
                                    <th aria-label="会员等级" style="width: 15%;">会员等级</th>
                                    <th aria-label="性别" style="width: 5%;">性别</th>
                                    <th aria-label="手机号" style="width: 10%;">手机号</th>
                                    <th aria-label="积分" style="width: 10%;">积分</th>
                                    <th aria-label="注册来源" style="width: 10%;">注册来源</th>
                                    <th aria-label="注册时间" style="width: 15%;">注册时间</th>
                                    <th aria-label="操作" style="width: 10%;">操作</th>
                                </tr>
                            </thead>
                            <tbody>
                                <tr class="gradeA odd" th:if="${#lists.isEmpty(pageObj.list)}">
                                    <td colspan="9" style="text-align: center">
                                        没有数据o&gt;^&lt;o
                                    </td>
                                </tr>
                                <tr class="gradeA odd" th:each="item : ${pageObj.list}">
                                    <td th:with="memberCardNum=${item.memberCardNum}" th:utext="${null == keyword ? memberCardNum : #strings.replace(memberCardNum,keyword,'<span style= &quot;color: red;font-weight:bold&quot;>'+ keyword +'</span>')}"></td>
                                    <td th:with="memberName=${item.memberName}" th:utext="${null == keyword ? memberName : #strings.replace(memberName,keyword,'<span style= &quot;color: red;font-weight:bold&quot;>'+ keyword +'</span>')}"></td>
                                    <td th:with="name=${item.name}" th:utext="${null == keyword ? name : #strings.replace(name,keyword,'<span style= &quot;color: red;font-weight:bold&quot;>'+ keyword +'</span>')}"></td>
                                    <td th:text="${item.membeType}"></td>
                                    <td th:text="${item.gender==0 ? '男' : (item.gender==1 ? '女' : '保密')}"></td>
                                    <td th:with="phoneNum=${item.phone}" th:utext="${null == keyword ? phoneNum : #strings.replace(phoneNum,keyword,'<span style= &quot;color: red;font-weight:bold&quot;>'+ keyword +'</span>')}"></td>
                                    <td th:text="${item.integral}"></td>
                                    <td th:text="${item.source =='public_number'? '微信公众号':'其他'}"></td>
                                    <td th:text="${item.createTime}"></td>
                                    <td class="center">
                                        <shiro:hasPermission name="push_ticket_to_user">
                                            <a type="button" th:onclick="ticketPush([[${item.id}]],[[${item.memberName}]])" class="modal-trigger" data-toggle="modal" data-target="#ticketModel" title="推送优惠券"><i class="fa fa-ticket"></i></a>
                                        </shiro:hasPermission>
                                        <shiro:hasPermission name="edit_user">
                                            <a type="button" th:onclick="findById([[${item.id}]])" class="modal-trigger" data-toggle="modal" data-target="#myModal" id="user-details" title="编辑"><i class="glyphicon glyphicon-edit"></i></a>
                                        </shiro:hasPermission>
                                        <shiro:hasPermission name="freeze_user">
                                            <a type="button" th:onclick="lock_unlock([[${item.id}]],$(this))" th:title="${item.freeze == 0 ? '冻结' : '解除冻结'}"><i th:class="${item.freeze == 0 ? 'fa fa-unlock' : 'fa fa-lock'}"></i></a>
                                        </shiro:hasPermission>
                                        <a type="button" th:onclick="changeLevel([[${item.id}]],[[${item.levelStratum}]],[[${item.phone}]])" class="modal-trigger" data-toggle="modal" data-target="#changeLevel" title="修改会员等级"><i class="fa fa-vimeo"></i></a>

                                    </td>
                                </tr>
                            </tbody>
                        </table>
                        <div class="row">
                            <div class="col-sm-6">
                                <div class="dataTables_info" role="alert" aria-live="polite" aria-relevant="all"
                                     th:text="${'显示 '
                                      + (page * size + 1)
                                      + ' 到 '
                                      + ((page+1) lt totalPage ? (size + page * size) : (total % size == 0 ? total : (total % size + size * page)))
                                      + ' 项，共 '
                                      + total + ' 项 ' + totalPage + ' 页'}">
                                </div>
                            </div>
                            <div class="col-sm-6">
                                <div class="dataTables_paginate paging_simple_numbers">
                                    <ul class="pagination" th:if="${totalPage>1}">
                                        <li th:class="${page==0}?'paginate_button previous disabled':'paginate_button previous'">
                                            <a th:href="${(page==0)?'#':'/user/list?page='+page
                                             +'&pageSize='+size
                                             +'&keyword='+(null==keyword?'':keyword)
                                             +'&fromDate='+(null==fromDate?'':fromDate)
                                             +'&fromInt='+(null==fromInt?'':fromInt)
                                             +'&toInt='+(null==toInt?'':toInt)
                                             +'&toDate='+(null==toDate?'':toDate)}">上一页</a>
                                        </li>
                                        <li th:if="${totalPage<10}" th:each="i:${#numbers.sequence(1,totalPage)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/user/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)
                                            +'&fromDate='+(null==fromDate?'':fromDate)
                                            +'&fromInt='+(null==fromInt?'':fromInt)
                                            +'&toInt='+(null==toInt?'':toInt)
                                            +'&toDate='+(null==toDate?'':toDate)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:if="${page<4&&totalPage>=9}" th:each="i:${#numbers.sequence(1,9)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/user/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)
                                            +'&fromDate='+(null==fromDate?'':fromDate)
                                            +'&fromInt='+(null==fromInt?'':fromInt)
                                            +'&toInt='+(null==toInt?'':toInt)
                                            +'&toDate='+(null==toDate?'':toDate)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:if="${page>=4&&totalPage>=9&&page+5<totalPage}" th:each="i:${#numbers.sequence(page - 3,page + 5)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/user/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)
                                            +'&fromDate='+(null==fromDate?'':fromDate)
                                            +'&fromInt='+(null==fromInt?'':fromInt)
                                            +'&toInt='+(null==toInt?'':toInt)
                                            +'&toDate='+(null==toDate?'':toDate)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:if="${page>=4&&totalPage>=9&&page+5>=totalPage}" th:each="i:${#numbers.sequence(totalPage - 8,totalPage)}"
                                            th:class="${i==page+1?'active':''}">
                                            <a th:href="${'/user/list?page='+i
                                            +'&pageSize='+size
                                            +'&keyword='+ (null==keyword?'':keyword)
                                            +'&fromDate='+(null==fromDate?'':fromDate)
                                            +'&toDate='+(null==toDate?'':toDate)
                                            +'&fromInt='+(null==fromInt?'':fromInt)
                                            +'&toInt='+(null==toInt?'':toInt)}"
                                               th:text="${i}"></a>
                                        </li>
                                        <li th:class="${page+1==totalPage||totalPage<1}?'paginate_button next disabled':'paginate_button next'" >
                                            <a th:href="${(page+1==totalPage||totalPage<1) ? '#' : '/user/list?page='+(page+2)
                                             +'&pageSize='+size
                                             +'&keyword='+(null==keyword?'':keyword)
                                             +'&fromDate='+(null==fromDate?'':fromDate)
                                             +'&fromInt='+(null==fromInt?'':fromInt)
                                             +'&toInt='+(null==toInt?'':toInt)
                                             +'&toDate='+(null==toDate?'':toDate)}">下一页</a>
                                        </li>
                                    </ul>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<div class="modal fade in" id="ticketModel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content" style="width: 500px">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="ticketModelLabel"></h4>
            </div>
            <div class="modal-body" style="height: 300px">
                <div class="input-group">
                    <input value="" type="text" placeholder="输入关键词" class="input-sm form-control" id="search-ticket">
                    <span class="input-group-btn">
                        <button type="button" class="btn btn-sm btn-primary" id="search-ticket-btn"> 搜索</button>
                    </span>
                </div>
                <table class="table">
                    <thead style="display:table;width:100%;table-layout:fixed;">
                    <tr>
                        <th style="width: 20%;">LOGO</th>
                        <th style="width: 35%;">券名称</th>
                        <th style="width: 10%;">总量</th>
                        <th style="width: 15%;">类型</th>
                        <th style="width: 20%;">操作</th>
                    </tr>
                    </thead>
                    <tbody style="display:block;height:200px;overflow-y:auto;width: 100%;" id="inner">

                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<div class="modal fade in" id="addUser" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width: 400px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="userModalLabel">创建用户</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="register-form">
                    <div class="form-group">
                        <div class="col-sm-12">
                            <div class="input-group">
                                <input type="phone" onkeydown="if(event.keyCode==13){event.keyCode=0;event.returnValue=false;}" name="phone" placeholder="请输入手机号" class="input-sm form-control">
                                <span class="input-group-btn">
                                    <button type="button" class="btn btn-sm btn-primary" id="submit-register"> 提交</button>
                                </span>
                            </div>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

<div class="modal fade in" id="changeLevel" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog" style="width: 400px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="userLevel">用户等级</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" id="userLevelForm">
                    <div class="form-group">
                        <div class="input-group col-sm-12">
                            <select class="form-control" id="user-level-selector"></select>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-sm btn-primary" id="submit-level" onclick="saveLevel();">保存</button>
            </div>
        </div>
    </div>
</div>

<div class="modal fade in" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">用户信息</h4>
            </div>
            <div class="modal-body" style="height: 350px;overflow: auto">
                <form class="form-horizontal" id="user-form" method="post" action="/user/update">
                    <div class="form-group" style="display: none;">
                        <label>id</label>
                        <div>
                            <input name="id" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">用户名：</label>
                        <div class="col-sm-8">
                            <input placeholder="请输入用户名" name="memberName" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">手机号：</label>
                        <div class="col-sm-8">
                            <input name="phone" disabled placeholder="请输入手机号" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">会员卡号：</label>
                        <div class="col-sm-8">
                            <input name="memberCardNum" disabled placeholder="请输入会员卡号" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">物理卡号：</label>
                        <div class="col-sm-8">
                            <input name="memberPhyCardNum" placeholder="请输入物理卡号" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">注册时间：</label>
                        <div class="col-sm-8">
                            <input name="createTime" disabled placeholder="请输入注册时间" class="form-control">
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">真实姓名：</label>
                        <div class="col-sm-8">
                            <input name="name" placeholder="请输入真实姓名" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">邮箱：</label>
                        <div class="col-sm-8">
                            <input id="cemail" name="email" type="email" placeholder="请输入邮箱" class="form-control">
                        </div>
                    </div>
                    <div data-toggle="distpicker" id="area-selector" class="form-group">
                        <label class="col-sm-3 control-label">地区：</label>
                        <div class="col-sm-9 form-inline">
                            <select class="form-control input-sm" style="width: 111px;font-size: 13px" id="_provinces" name="provinces" data-province="-选择省-"></select>
                            <select class="form-control input-sm" style="width: 111px;font-size: 13px" id="_city" name="city" data-city="-选择市-"></select>
                            <select class="form-control input-sm" style="width: 111px;font-size: 13px" id="_area" name="area" data-district="-选择区-"></select>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">生日：</label>
                        <div class="col-sm-8">
                            <input type="text" autocomplete="off" readonly class="input-sm form-control" name="birthday" id="birthday" placeholder="会员生日">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">证件类型：</label>
                        <div class="col-sm-8">
                            <label class="radio-inline">
                                <input type="radio" name="documenType" value="identityCard">身份证
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="documenType" value="armymanCard">军官证
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="documenType" value>未填写
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">证件号：</label>
                        <div class="col-sm-8">
                            <input name="identityNum" placeholder="请输入证件号" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">家庭住址：</label>
                        <div class="col-sm-8">
                            <input name="homeAddress" placeholder="请输入家庭住址" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">工作：</label>
                        <div class="col-sm-8">
                            <input name="job" placeholder="请输入工作(10个字以内)" maxlength="10" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">爱好：</label>
                        <div class="col-sm-8">
                            <input name="favorite" placeholder="请输入爱好(10个字以内)" maxlength="10" class="form-control">
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">性别：</label>
                        <div class="col-sm-8">
                            <label class="radio-inline">
                                <input type="radio" name="gender" value="0">男
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="gender" value="1">女
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">婚否：</label>
                        <div class="col-sm-8">
                            <label class="radio-inline">
                                <input type="radio" name="married" value="1">是
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="married" value="0">否
                            </label>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">有无子女：</label>
                        <div class="col-sm-8">
                            <label class="radio-inline">
                                <input type="radio" name="children" value="1">是
                            </label>
                            <label class="radio-inline">
                                <input type="radio" name="children" value="0">否
                            </label>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary" id="submit-table">提交</button>
            </div>
        </div>
    </div>
</div>
</body>
<script src="/js/plugins/distpicker/distpicker.js"></script>
<script src="/js/plugins/validate/jquery.validate.min.js"></script>
<script src="/js/common/form-validate.min.js"></script>
<script th:inline="javascript">

    $(function () {
        let selectorHtml = '<option value="">请选择等级</option>';
        $.ajax({
            url: ipDomain + '/quanquan-user/user_level/list',
            type: "POST",
            success: function (res) {
                if (res.resCode === 0) {
                    let levels = res.data;
                    levels.forEach(level => {
                        selectorHtml += '<option value="' + level.levelStratum + '">' + level.levelName + '</option>'
                    })
                    $("#user-level-selector").html(selectorHtml);
                } else {
                    console.log("获取等级列表失败");
                }
            }
        })
    })


    function lock_unlock(userId,e) {
        $.ajax({
            url: "/user/freeze",
            type: "get",
            data: {id:userId,status:status},
            dataType: "json",
            success: function (res) {
                if (res.data.freeze == 0) {
                    e.attr('title','冻结');
                    e.children('i').removeClass('fa-lock');
                    e.children('i').addClass('fa-unlock');
                    layer.msg("已解除冻结"+res.data.phone,{icon: 1,time: 1500,shade : [0.5 , '#000' , true]});
                }
                if (res.data.freeze == 1) {
                    e.attr('title','解除冻结');
                    e.children('i').removeClass('fa-unlock');
                    e.children('i').addClass('fa-lock');
                    layer.msg("已冻结"+res.data.phone,{icon: 1,time: 1500,shade : [0.5 , '#000' , true]});
                }
            }
        });
    }
    $("#submit-register").click(()=>{
        $.ajax({
            url:"/user/create",
            type:"post",
            data: $('#register-form').serialize(),
            dataType:"json",
            success : function(data) {
                if (data.resCode == 0) {
                    layer.msg(data.resMsg,{icon: 1,time: 1000,shade : [0.5 , '#000' , true]});
                    $('#addUser').modal('hide');
                } else {
                    layer.msg(data.resMsg,{icon: 15,time: 1000,shade : [0.5 , '#000' , true]});
                }
            },
            error: function () {
                layer.alert("提交错误")
            }
        })
    });
    //初始化地区选择
    $('#area-selector').distpicker();
    let userId = '';
    function ticketPush(id,name) {
        if (null == name) {
            name = '未命名';
        }
        userId = '"' + id + '"';
        $("#ticketModelLabel").html("券推送给用户：" + name);
        setData();
    }
    function setData() {
        $("#inner").html('');
        let _this = $("#search-ticket");
        let keyword = _this.val();
        layer.load(1);
        setTimeout(function () {
            $.ajax({
                url:"/coupon/search?keyword=" + keyword + "&activeId=",
                type:"get",
                success: function (res) {
                    let list = res.data.list;
                    layer.closeAll('loading');
                    if (null == list) {
                        return;
                    }
                    let str = '';
                    list.forEach(obj => {
                        let objId = '"' + obj.id + '"';
                        str += "<tr style='display:table;width:100%;table-layout:fixed;'>" +
                            "<td style='display:none;'>" +obj.id + "</td>" +
                            "<td style='width: 20%'><img style='height: 40px' src='" + obj.image + "' onerror=\"this.src='/img/default_coup.png'\"></td>" +
                            "<td style='width: 35%'>" + obj.name + "</td>" +
                            "<td style='width: 10%'>" + (obj.sumTatal == null ? '∞' : obj.remainTotal) + "</td>" +
                            "<td style='width: 15%'>" + (obj.type == 1 ? '优惠券' : '停车券') + "</td>" +
                            "<td style='width: 20%'><a type='button' href='javascript:pushCoupon(" + userId + "," + objId +");' class='btn btn-primary btn-xs'>推送</a></td>" +
                            "</tr>"
                    });
                    $("#inner").html(str);
                },
                error : function () {
                    layer.closeAll('loading');
                }
            });
        },500);
    }
    $("#search-ticket-btn").click(function () {
        setData();
    });
    $("#search-ticket").on("keydown",function (e) {
        if (e.keyCode != 13) {
            return;
        }
        setData();
    });

    let userId1 = '';
    let levelIndex = '';

    function changeLevel(id,lvIndex, name) {
        $("#userLevel").html("设置[" + name + "]会员等级");
        let el = 'user-level-selector option[value="' + lvIndex + '"]';
        $('#' + el).attr("selected",true);
        userId1 = id;
        levelIndex = lvIndex;
    }

    function saveLevel() {
        if (levelIndex === '') {
            layer.msg("请选择会员等级",{icon: 11,time: 1000,shade : [0.5 , '#000' , true]})
        }
        levelIndex = $("#user-level-selector").val();
        $.ajax({
            url: ipDomain + '/quanquan-user/user_level/update_management',
            type: 'POST',
            data: {'levelStratum': levelIndex, 'userId': userId1},
            success: function (res) {
                if (res.resCode === 0 && res.data != -1) {
                    $('#changeLevel').modal('hide');
                    layer.msg("用户会员等级已修改",{icon: 1,time: 1000,shade : [0.5 , '#000' , true]});
                    window.location.reload(true);
                } else if (res.data === -1) {
                    $('#changeLevel').modal('hide');
                    layer.msg("会员不能降级",{icon: 11,time: 1000,shade : [0.5 , '#000' , true]});
                }
            }
        }).error(function () {
            layer.msg("服务端异常，请联系开发人员",{icon: 11,time: 1000,shade : [0.5 , '#000' , true]});
        });
    }



    function pushCoupon(userId, coupId) {
        let num = prompt("请输入优惠券数量","1");
        if (null == num) {
            return;
        }
        if (isNaN(num)) {
            layer.msg('请输入正确的数字',{icon: 15,time: 1000,shade : [0.5 , '#000' , true]});
        }
        let postData = {userId:userId,id:coupId,count:num};
        $.ajax({
            url:"/coupon/push",
            data:JSON.stringify(postData),
            contentType: 'application/json',
            type:"POST",
            success: function (data) {
                let code = data.resCode;
                if(code == 0) {
                    layer.alert("发券成功");
                    setData();
                }
                else {
                    layer.alert(data.resMsg);
                }
            }
        });
    }
    function findById(id) {
        $.get(
            "/user/get?id=" + id,
            function (res) {
                $("#myForm").loadData(res.data);
                $("#_provinces").val(res.data.provinces);
                $("#_provinces").trigger("change");
                $("#_city").val(res.data.city);
                $("#_city").trigger("change");
                $("#_area").val(res.data.area);
            }
        );
    }
    $("#submit-table").click(() => {
        try {
            $("#user-form").ajaxSubmit(data => {
               if (data.resCode == 0) {
                   layer.alert('会员信息修改成功');
                   window.location.href = '/user/list';
               } else {
                   layer.alert(data.msg)
               }
            });
        } catch (e) {
            layer.alert('系统异常，修改失败')
        }

    });
    $("#page_size_selector").change(function () {
        let fromDate = $("#start_date").val();
        let toDate = $("#end_date").val();
        let fromInt = $("#from_int").val();
        let toInt = $("#to_int").val();
        let selected = $(this).val();
        window.location.href = initUrl(0,selected,'',fromDate,toDate,fromInt,toInt);
    })
    $("#search_bar").keydown(function (e) {
        let fromDate = $("#start_date").val();
        let toDate = $("#end_date").val();
        let fromInt = $("#from_int").val();
        let toInt = $("#to_int").val();
        if (e.keyCode == 13) {
            let size = $("#page_size_selector").val();
            let keyword = $(this).val();
            window.location.href = initUrl(0,size,keyword,fromDate,toDate,fromInt,toInt);
        }
    })
    $("#search-btn").click(function () {
        let fromDate = $("#start_date").val();
        let toDate = $("#end_date").val();
        let fromInt = $("#from_int").val();
        let toInt = $("#to_int").val();
        let size = $("#page_size_selector").val();
        let keyword = $("#search_bar").val();
        window.location.href = initUrl(0,size,keyword,fromDate,toDate,fromInt,toInt);
    })
    function initUrl(page,size,key,fromDate,toDate,fromInt,toInt) {
        if (null == page) {
            page = 0;
        }
        return "/user/list?page="+ page +"&pageSize=" + size + "&keyword=" + key + "&fromDate=" + fromDate + "&toDate=" + toDate + "&fromInt=" + fromInt + "&toInt=" + toInt
    }
</script>
</html>